define(
[],
function(){
	
	//Haversine is a func to calculate great circle distance between to point
	//This specific function is specialized for Earth (R=6371 (in km))
	Math.haversine = function(lon1, lat1, lon2, lat2) {
        var R = 6371; // km
        var dLat = Math.degToRad(lat2-lat1);
        var dLon = Math.degToRad(lon2-lon1);
        lat1 = Math.degToRad(lat1);
        lat2 = Math.degToRad(lat2);

        var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                Math.sin(dLon/2) * Math.sin(dLon/2) * 
                Math.cos(lat1) * Math.cos(lat2);
        var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
        var d = R * c;
        return d;
	}

	Math.createLatLonToMeterConverter = function(minlon, minlat) {
		return {
			latToMeter: function(val) { 
                return Math.haversine(minlon, minlat, minlon, val) * 1000 *
                    ((val - minlat < 0) ? -1 : 1);
            },
            lonToMeter: function(val) {
                return Math.haversine(minlon, minlat, val, minlat) * 1000 *
                    ((val - minlon < 0) ? -1 : 1);
            }
		}
	}
});